package com.css.dzj.dzjdzqs.modules.apaction.apcheck.service.impl;

import com.alibaba.fastjson.JSON;
import com.css.dzj.dzjdzqs.common.util.HttpClientUtil;
import com.css.dzj.dzjdzqs.modules.apaction.apcheck.Vo.ApCheckVo;
import com.css.dzj.dzjdzqs.modules.apaction.apcheck.entity.ApCheckEntity;
import com.css.dzj.dzjdzqs.modules.apaction.apcheck.entity.QApCheckEntity;
import com.css.dzj.dzjdzqs.modules.apaction.apcheck.mapper.ApCheckMapper;
import com.css.dzj.dzjdzqs.modules.apaction.apcheck.service.ApCheckService;
import com.querydsl.jpa.impl.JPAQueryFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Author WT
 * @Date 2020/6/28
 */

@Service
public class ApCheckServiceImpl implements ApCheckService {

    @Autowired
    JPAQueryFactory jpaQueryFactory;
    @Autowired
    private ApCheckMapper apCheckMapper;
    @Autowired
    HttpServletRequest request;

    @Value("${AP_URL}")
    private String apUrl;

    @Override
    @Transactional
    public void add(List<ApCheckVo> apCheckVos) {

       try {
           for(ApCheckVo apCheckVo :apCheckVos){
               ApCheckEntity apCheck = new ApCheckEntity();
               apCheck.setActionId(apCheckVo.getActionId());
               apCheck.setRecordUniqueIdentity(apCheckVo.getRecordUniqueIdentity());
               apCheck.setSuperviseItemImplementCode(apCheckVo.getSuperviseItemImplementCode());
               apCheck.setSuperviseItemCheckICode(apCheckVo.getSuperviseItemCheckIcode());
               apCheck.setCheckActionName(apCheckVo.getCheckActionName());
               apCheck.setCheckActionCode(apCheckVo.getCheckActionCode());
               apCheck.setImplementInstitution(apCheckVo.getImplementInstitution());
               apCheck.setImplementInstitutionCode(apCheckVo.getImplementInstitutionCode());
               apCheck.setEntrustDept(apCheckVo.getEntrustDept());
               apCheck.setEntrustDeptCode(apCheckVo.getEntrustDeptCode());
               apCheck.setSuperviseObject(apCheckVo.getSuperviseObject());
               apCheck.setAdministrativeCp(apCheckVo.getAdministrativeCp());
               apCheck.setAdministrativeCpNa(apCheckVo.getAdministrativeCpNa());
               apCheck.setAdministrativeCpCeType(apCheckVo.getAdministrativeCpCeType());
               apCheck.setAdministrativeCpUiCode(apCheckVo.getAdministrativeCpUiCode());
               apCheck.setAddressRegistered(apCheckVo.getAddressRegistered());
               apCheck.setAddressOperating(apCheckVo.getAddressOperating());
               apCheck.setAreaNumber(apCheckVo.getAreaNumber());
               apCheck.setCheckForm(apCheckVo.getCheckForm());
               apCheck.setCheckType(apCheckVo.getCheckType());
               apCheck.setCheckMode(apCheckVo.getCheckMode());
               apCheck.setCheckResult(apCheckVo.getCheckResult());
               apCheck.setCheckDate(apCheckVo.getCheckDate());
               apCheck.setCheckPersonnel(apCheckVo.getCheckPersonnel());
               apCheck.setCheckPersonnelCode(apCheckVo.getCheckPersonnelCode());
               apCheck.setSubmittedDate(apCheckVo.getSubmittedDate());
               apCheckMapper.save(apCheck);
           }
       }catch (Exception e){
           e.printStackTrace();
       }


    }
    @Override
    @Transactional
    public void pushtCheck() {

        try{
            String msg = HttpClientUtil.doGet(apUrl+"/check/getApList");
            List<ApCheckVo> apCheckEntityList = JSON.parseArray(msg, ApCheckVo.class);
            if(null!=apCheckEntityList && apCheckEntityList.size()>0){
                add(apCheckEntityList);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }

}
